//
//  LGDeviceOrderDetailCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2025/2/24.
//

#import "LGDeviceOrderDetailCell.h"

@interface LGDeviceOrderDetailCell()
/**   */
@property (nonatomic , strong)UIView *backView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *contentLabel;
/**   */
@property (nonatomic , copy)NSString *superKey;
/**   */
@property (nonatomic , copy)NSString *key;

@end

@implementation LGDeviceOrderDetailCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    [super setDataDic:dataDic];
    self.key = LGNSString(dataDic[@"key"]);
    self.superKey = LGNSString(dataDic[@"superkey"]);
    self.titleLabel.text = LGNSString(dataDic[@"title"]);
}

-(void)setResultDic:(NSDictionary *)resultDic{
    _resultDic = resultDic;
    NSString *result = @"";
    if (self.superKey.length>0 && [resultDic[self.superKey] isKindOfClass:[NSDictionary class]]) {
        NSDictionary *tempDic = resultDic[self.superKey];
        result = LGNSString(tempDic[self.key]);
    }else{
        result = LGNSString(resultDic[self.key]);
    }
    
    self.contentLabel.text = [result isEmptyString]?@"--":result;
    
    //state:10-待领取 、20-待发货 、 30-已发货 、 40-已寄出 、 50-已入库 、 101-已取消 、 102-已赠送（续包赠送） 、 103-待归还 、104-回收失败
    if (([self.key isEqualToString:@"status_name"]||[self.key isEqualToString:@"refund_state_name"]) && ([result isEqualToString:@"生效中"] || [result isEqualToString:@"未生效"] || [result isEqualToString:@"未退款"])) {
        self.contentLabel.textColor = [UIColor colorWithString:@"#4C87FD"];
        
    }else if (([self.key isEqualToString:@"state_name"] || [self.key isEqualToString:@"deliver_status_name"]) && ([result isEqualToString:@"待领取"] || [result isEqualToString:@"待发货"]||[result isEqualToString:@"待回收"] || [result isEqualToString:@"已寄出"])) {
        self.contentLabel.textColor = [UIColor colorWithString:@"#4C87FD"];
        
    }else{
        self.contentLabel.textColor = [UIColor colorWithString:@"#909399"];
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.type = LGPositionTypeMiddle;
    [self.contentView addSubview:self.backView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.contentLabel];
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(-2);
        make.bottom.equalTo(self.contentView).offset(2);
        make.left.equalTo(self.contentView).offset(viewPix(28));
        make.right.equalTo(self.contentView).offset(-viewPix(28));
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(40));
        make.top.equalTo(self.contentView).offset(viewPix(8));
    }];
    
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(viewPix(120));
        make.right.equalTo(self.contentView).offset(viewPix(-32));
        make.bottom.equalTo(self.contentView).offset(viewPix(-8));
        make.top.equalTo(self.titleLabel);
    }];
    
    
}

-(UIView *)backView{
    if(!_backView){
        _backView = [[UIView alloc]init];
        _backView.backgroundColor = [UIColor colorWithString:@"#F7F9FB"];
        _backView.cornerRidus = 5;
    }
    return _backView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#606266" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}

-(UILabel *)contentLabel{
    if(!_contentLabel){
        _contentLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:0];
    }
    return _contentLabel;
}

@end
